package com.caipiao.crawler.pailie;

import com.alibaba.fastjson.JSON;
import com.caipiao.crawler.mapper.LotteryNumberMapper;
import com.caipiao.crawler.model.LotteryNumber;
import com.caipiao.util.DBTools;
import org.apache.ibatis.session.SqlSession;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

/**
 * Created by adminitrator on 2018/7/28.
 */
public class Pailie5DetailPipeline implements Pipeline {

    @Override
    public synchronized void process(ResultItems resultItems, Task task) {
        LotteryNumber m5 = resultItems.get("model5");
        System.err.println("pipe process:" + Thread.currentThread().getId());
        if(m5 ==null) {
            return;
        }
        commit(m5);
    }

    public void commit(LotteryNumber model5) {
        System.err.println("commit");
        System.err.println(JSON.toJSONString(model5));
        SqlSession session = DBTools.getSession();
        LotteryNumberMapper mapper = session.getMapper(LotteryNumberMapper.class);
        mapper.updetaByModelForPlw(model5);
        session.commit();
        session.close();
    }

}
